package com.yzkj.siot.service.impl;

import cn.hutool.json.JSONUtil;
import com.yzkj.siot.cache.SysSettingCache;
import com.yzkj.siot.domain.TenantDeviceData;
import com.yzkj.siot.facade.ProductFacade;
import com.yzkj.siot.service.TaskTreadService;
import com.yzkj.siot.service.TenantDeviceDataService;
import com.yzkj.siot.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TaskTreadServiceImpl implements TaskTreadService {

    @Autowired
    ProductFacade productFacade;
    @Resource
    private RedisUtil redisUtil;

    @Override
    public void deviceDataBatchSaveToCache(TenantDeviceDataService service, List<TenantDeviceData> entities) {
        if (!CollectionUtils.isEmpty(entities)) {
            redisUtil.set("tenant_device_data:" + entities.get(0).getTenantId() + ":" + entities.get(0).getDeviceId(),
                    JSONUtil.toJsonStr(entities),
                    SysSettingCache.setting.getDataHealthTime());
        }
    }
}
